package com.example.houduan.Controller;

import com.example.houduan.Pojo.RequiredMaterial;
import com.example.houduan.Service.RequiredMaterialService;
import com.example.houduan.Utils.PageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@Controller
@CrossOrigin
public class RequiredMaterialController {
    @Autowired
    RequiredMaterialService requiredMaterialService;

    @RequestMapping("/getRequiredMaterialPage")
    @ResponseBody
    public PageModel getRequiredMaterialPage(@RequestParam int num,int size){
        return requiredMaterialService.getRequiredMaterialPage(num, size);
    }

    @RequestMapping("/deleteRequiredMaterial")
    @ResponseBody
    public String deleteRequiredMaterial(@RequestParam Integer meterial_id){
        if (requiredMaterialService.deleteRequiredMaterial(meterial_id)==0){
            return "删除失败";
        }else{
            return "删除成功";
        }
    }

    @RequestMapping("/updateRequiredMaterial")
    @ResponseBody
    public String updateRequiredMaterial(@RequestBody RequiredMaterial requiredMaterial){
        requiredMaterial.setUpdate_time(LocalDateTime.now());
        if(requiredMaterialService.updateRequiredMaterial(requiredMaterial)==0){
            return "更新失败";
        }else{
            return "更新成功";
        }
    }

    @RequestMapping("/addRequiredMaterial")
    @ResponseBody
    public String addRequiredMaterial(@RequestBody RequiredMaterial requiredMaterial){
        requiredMaterial.setUpdate_time(LocalDateTime.now());
        requiredMaterial.setCreate_time(LocalDateTime.now());
        if(requiredMaterialService.addRequiredMaterial(requiredMaterial)==0){
            return "添加失败";
        }else {
            return "添加成功";
        }
    }

} 